<?php /**
* 
*/
class komentar extends record
{
	
	function __construct()
	{
		parent::__construct();
		$this->namaTabel ='komentar';
	}
	function getAllComment(){
		return $this->showDisplayMsg(0,'all');

	}
	function displayKomentar($data,$admin=false){
		$str ='';
		foreach ($data as $value) {			
			$str .='<div class="list_image '.($value['parent']==0?'first_comment':'comment_reply').'">';
			$str .='<p class="contact_nm">'.$value['nama'].' | '.$value['waktu'].' </p>';
			$str .='<p class="contact_tm">Subject: '.$value['judul'].'</p>';
			$str .='<p class="contact_msg">';
			$str .=$value['pesan'];
			$str .='</p>';
			$str .='<p>
			<a href="'.(($admin==true)?BASEURLADMIN.'?v=customer&p=replycomment&to='.$value['id']:BASEURL.'?v=contact&reply=display&to='.$value['id']).'" class="button">Balas</a>';
			if($admin==true){
				$str .=	'<a href="'.BASEURL.'proses/komentar.php?on=approve&id='.$value['id'].'&status='.$value['status'].'"
				 class="'.(($value['status']==1)?'button':'button_2').'">'.(($value['status']==1)?'Sembunyikan':'Tampilkan').'</a>';
			}
			$str .='</p>';
			$str .='</div>';
			$str .=(isset($value['balas']) && is_array($value['balas']))?$this->displayKomentar($value['balas'],$admin):'';
		};
		return $str;
	}
	function showDisplayMsg($parentID=0,$status=1){
		if($status=='all'){
			
		}else{

		$w['status']=$status;	
	};		
		
		$w['parent']=$parentID;
		//($fields = '*', $cond = array(), $limit = null, $start = null, $orderBy = null, $orderType = 'ASC', $condStr = null, $arrSearch = array());
		$this->get('*',$w,null,null,'waktu','desc');
		$sxC=$this->execute();
		if( $sxC['success']==true && $sxC['total']>0 ){
			$i=0;
			foreach ($sxC['result'] as $value) {
				$ret[$i]['id']=$value['id'];
				$ret[$i]['nama']=$value['nama'];
				$ret[$i]['waktu']=$value['waktu'];
				$ret[$i]['pesan']=$value['pesan'];
				$ret[$i]['parent']=$value['parent'];
				$ret[$i]['email']=$value['email'];
				$ret[$i]['judul']=$value['judul'];
				$ret[$i]['status']=$value['status'];
				$ret[$i]['balas']=$this->showDisplayMsg($value['id'],$status);
				$i++;
			}
		}
		else{
			$ret=null;
		};
		return $ret;
	}
} 
$objKomentar = new komentar();